<?php

namespace common\models\business;

use common\models\db\Reviews;
use common\models\inter\InterBusiness;
use common\models\output\Response;

class ReviewsBusiness implements InterBusiness {

    /**
     * Menu
     * @param type $id
     * @return type
     */
    public static function get($id) {
        return Reviews::findOne($id);
    }

    /**
     * mget
     * @param type $ids
     * @return type
     */
    public static function mGet($ids) {
        return Reviews::find()->andWhere(["id" => $ids]);
    }

    /**
     * Thay đổi trạng thái partners
     * @param type $id
     */
    public static function changeActive($id) {
        $album = self::get($id);
        if ($album == null) {
            return new Response(false, "Album không tồn tại");
        }
        $album->active = $album->active == 1 ? 0 : 1;
        $album->save(false);
        return new Response(true, "Album " . $album->name . $album->active ? "đã mở khóa" : "đã khóa", $album);
    }

    public static function changeHome($id) {
        $album = self::get($id);
        if ($album == null) {
            return new Response(false, "Album không tồn tại");
        }
        $album->home = $album->home == 1 ? 0 : 1;
        $album->save(false);
        return new Response(true, "Album " . $album->name . $album->active ? "đã hiển thị" : "đã khóa", $album);
    }

    /**
     * Xóa Partners theo id
     * @param type $id
     */
    public static function remove($id) {
        $album = self::get($id);
        if ($album == null) {
            return new Response(false, "Album không tồn tại");
        }
        ImageBusiness::deleteByTarget($album->id);
        $album->delete();
        return new Response(true, "Xóa album thành công");
    }

}
